

public class ThreadTest {

    public static void main(String[] args) throws Exception{
        //new一个非守护线程
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while(true) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("Thread is running...");
                }
            }
        });
        //启动线程
        thread.setDaemon(true);

        thread.start();
        Thread.sleep(5000);

        //main线程的结束
        System.out.println("main method end...");
    }

}